//
//  XYHttpRequest.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/3/22.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "XYHttpRequest.h"
#import "NSObject+AFNetworking.h"
#import <AFNetworking.h>
#import "DeviceInfo.h"
@implementation XYHttpRequest

//查询虚拟资金(红包 抵用券)
+ (void)dataRequestGetVirtualMoneyWithDic:(NSDictionary*)para success:(success)success failure:(failure)failure
{
    [NSObject wb_showBusy];
    [self wb_POST:CommonPath(@"appVirtualMoney/virtualMoneys") params:para success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//注册获取短信验证码
+ (void)dataRequestGetMessageWithPhone:(NSString *)phone codeLength:(NSInteger)length success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    params[@"phone"]=phone;
    params[@"type"]=@"0";
    params[@"codeType"]=@"041";
    params[@"moduleType"]=@"0";
    [NSObject wb_showBusy];
    if (length==4) {
        params[@"codeLength"] = @(length);
    }
    [self wb_POST:CommonPath(@"appAccount/mobile/sendCode") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//注册新用户
+ (void)dataRequestRegisterWithphone:(NSString*)phone withPassword:(NSString*)password withSmsCode:(NSString*)smsCode success:(void(^)(id))success failure:(void(^)(NSError *))failure{
    
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    params[@"username"] = phone;
    params[@"pwd"] = password;
    params[@"mobile"] = phone;
    params[@"code"] = smsCode;
    params[@"moduleType"] = @"0";
    NSString *deviceJsonStr = [Factory dictionaryToJson:[DeviceInfo getDeviceInfo]];
    params[@"deviceInfo"] = deviceJsonStr;
    
    NSLog(@"%@",[DeviceInfo getLocationPower]);
    
    params[@"eusername"] = @"123";
    params[@"refereeInfoId"] = @"321";
    params[@"custSource"] = @"111";
//    params[@"deviceCode"] = [Factory getUUID];
//    params[@"registration_id"] = [[NSUserDefaults standardUserDefaults] objectForKey:RegistrationID]==nil?@"":[[NSUserDefaults standardUserDefaults] objectForKey:RegistrationID];
    [NSObject wb_showBusy];
    [self wb_POST:CommonPath(@"appAccount/appRegister") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
    }];
}

//用户登录
+ (void)dataRequestLoginWithPhone:(NSString*)phone withPassword:(NSString*)password success:(void(^)(id))success failure:(void(^)(NSError *))failure{
    
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    params[@"username"] = phone;
    params[@"password"] = password;
    params[@"loginIp"] = @"192.168.1.1";
//    params[@"registration_id"]=[[NSUserDefaults standardUserDefaults] objectForKey:RegistrationID]==nil?@"":[[NSUserDefaults standardUserDefaults] objectForKey:RegistrationID];
//    params[@"deviceCode"]=[Factory getUUID];
    [NSObject wb_showBusy];
    [self wb_POST:CommonPath(@"appAccount/appLogin") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
    }];
}

//投资列表
+ (void)dataRequestInvestWithiInvestRate:(NSString *)investRate risks:(NSString *)risks periods:(NSString *)periods level:(NSString *)level sortField:(NSString *)sortField sortType:(NSString *)sortType page:(NSString *)page rows:(NSString *)rows success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    params[@"investRate"] = investRate;//利率
    params[@"risks"] = risks;//风险等级 0 低风险 1 中风险 2 高风险
    params[@"periods"] = periods;//期限
    params[@"level"] = level;//智能分级 0 AA 1 A 2 B 3 C 4 D 5 E 6 F
    
    params[@"sortField"] = sortField;//排序字段 level 等级排序  rate 利率排序  periods 期限排序  progress  进度排序
    params[@"sortType"] = sortType;//排序类型  1 升序 2降序
    
    params[@"page"] = page;
    params[@"rows"] = rows;
    
    [NSObject wb_showBusy];
    [self wb_POST:CommonPath(@"appInvest/appInvestList") params:params success:^(id responseObj) {
    [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
    [NSObject wb_hideProgress];
        failure(error);
    }];
}

//修改登录密码
+ (void)dataRequestWithNewPwd:(NSString *)newPwd oldPwd:(NSString *)oldPwd success:(success)success failure:(failure)failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"oldPw"] = oldPwd;
    params[@"newPw"] = newPwd;
    params[@"signature"] = @"";
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appChangeLoginPw") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//修改手机号码
+ (void)dataRequestWithModifiedPhoneNumber:(NSString *)phone code:(NSString*)code uccess:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"mobile"] = phone;
    params[@"code"] = code;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appCertification/appChangeRegisterMobile") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//获取用户对象接口
+ (void)dataRequestWithGetUserInfoSuccess:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appGetUser") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//新增交易密码
+ (void)dataRequestWithAddTraderPwd:(NSString *)pwd success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"newPw"] = pwd;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appAddTraderPw") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//验证交易密码
+ (void)dataRequestWithCheckTraderOldPwd:(NSString *)oldPwd success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"oldPw"] = oldPwd;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appcheckTraderPw") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//修改交易密码
+ (void)dataRequestWithChangeTraderPw:(NSString *)oldPwd newPw:(NSString *)newPw success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"oldPw"] = oldPwd;
    params[@"newPw"] = newPw;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appChangeTraderPw") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//投标余额查询
+ (void)dataRequestWithGetCustBalanaSuccess:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/myInvest/appGetCustBalanae") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//投标预期收益查询
+ (void)dataRequestWithGetExceptedReturnCrmOrderId:(NSString*)crmorderid Amount:(NSString*)amount GuarantorStatus:(NSInteger)guarantorStatus success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"crmOrderId"] = crmorderid;
    params[@"amount"] = amount;
    params[@"guarantorStatus"] = @(guarantorStatus);
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appInvest/appGetExceptedReturn") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
// 确认投标
+ (void)dataRequestWithAppDoInvestCrmOrderId:(NSString*)crmorderid custInfoId:(NSString*)custInfoId prdId:(NSString*)prdId amount:(NSString*)amount actualAmount:(NSString*)actualAmount guarantorStatus:(NSInteger)guarantorStatus success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"crmOrderId"] = crmorderid;
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"amount"] = amount;
    params[@"custInfoId"] = custInfoId;
    params[@"prdId"] = prdId;
    params[@"actualAmount"] = actualAmount;
    params[@"guarantorStatus"] = @(guarantorStatus);
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appInvest/appDoInvest") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//投资人首次绑卡接口
+ (void)dataRequestWithCertificationBindCardCustName:(NSString *)custName custIc:(NSString *)custIc bankName:(NSString *)bankName custBindCard:(NSString *)custBindCard custBindCardMobile:(NSString *)custBindCardMobile code:(NSString *)code
                                         defaultCard:(NSNumber*)defaultCard success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"custName"] = custName;
    params[@"custIc"] = custIc;
    params[@"bankName"] = bankName;
    params[@"custBindCard"] = custBindCard;
    params[@"custBindCardMobile"] = custBindCardMobile;
    params[@"cardType"] = @"0";  //0储蓄卡 1信用卡
    params[@"code"] = code;
    params[@"defaultCard"] = defaultCard;
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appCertificationBindCard") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//充值接口
+ (void)dataRequestWithRechargeMoney:(NSString *)money success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"amount"] = money;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appRechargeMoneyQ") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//提现接口
+ (void)dataRequestWithDrawMoney:(NSString *)money success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    params[@"amount"] = money;
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appGetWithdrawHtml") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//默认银行卡信息
+ (void)dataRequestWithDefaultBankCardsuccess:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    //params[@"custId"] = @"df0bf16c68f84eff8367483c633fcf8b";
    params[@"cardType"] = @"0";  //0储蓄卡 1信用卡
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appDefaultBankCard") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//设置默认银行卡
+ (void)dataRequestSetDefaultBankCardWithCardType:(NSInteger)type cardId:(NSString*)cardid success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    //params[@"custId"] = @"df0bf16c68f84eff8367483c633fcf8b";
    params[@"cardType"] = @(type);  //0储蓄卡 1信用卡
    params[@"cardId"] = cardid;
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appUpdateDefaultBankCard") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//我的银行卡列表
+ (void)dataRequestWithMyBankCardListType:(NSInteger)type success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    //params[@"custId"] = @"df0bf16c68f84eff8367483c633fcf8b";
    params[@"cardType"] = @(type);  //0储蓄卡 1信用卡
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/appBankCard") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//支持的银行卡列表
+ (void)dataRequestWithSupportBankCardListType:(NSInteger)type success:(success)success failure:(failure)failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    params[@"custId"] = [[NSUserDefaults standardUserDefaults] objectForKey:CustId];
    //params[@"custId"] = @"df0bf16c68f84eff8367483c633fcf8b";
    params[@"type"] = @(type);  //0储蓄卡 1信用卡
    
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appAccount/appBank/getSupportCard") params:params success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
//风险等级
+ (void)dataRequestWithGetInvestRisksuccess:(success)success failure:(failure)failure
{
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appInvest/appGetInvestRisks") params:nil success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}

//只能分级
+ (void)dataRequestWithGetGetInvestLevelsuccess:(success)success failure:(failure)failure
{
    [NSObject wb_showBusy];
    [NSObject wb_POST:CommonPath(@"appInvest/appGetInvestLevel") params:nil success:^(id responseObj) {
        [NSObject wb_hideProgress];
        success(responseObj);
    } failure:^(NSError *error) {
        [NSObject wb_hideProgress];
        failure(error);
    }];
}
@end
